axios.get('/my/userinfo', {
  // headers: {
  //   Authorization: localStorage.getItem('token')
  // }
}).then(({ data: res }) => {
  console.log(res);

  if (res.status === 1 && res.message === "身份认证失败！") {
    location.href = '/login.html'
  }

  let name = res.data.nickname || res.data.username
  console.log(name);

  if (res.data.user_pic) {
    $('.avatar').prop('src', res.data.user_pic).show()
  } else {
    $('.text-avatar-box').show()
    $('.text-avatar').html(name[0].toUpperCase())
  }
  $('#welcome').text(`欢迎${name}`)
})
getUserInfo()
function getUserInfo() {
  axios.get('/my/userinfo', {
    // headers: {
    //   Authorization: localStorage.getItem('token')
    // }
  }).then(({ data: res }) => {
    console.log(res);

    if (res.status === 1 && res.message === "身份认证失败！") {
      location.href = '/login.html'
    }

    let name = res.data.nickname || res.data.username
    console.log(name);

    if (res.data.user_pic) {
      $('.avatar').prop('src', res.data.user_pic).show()
      $('.text-avatar-box').hide()


    } else {
      $('.text-avatar-box').show()
      $('.text-avatar').html(name[0].toUpperCase())

      $('.avatar').show()
    }
    $('#welcome').text(`欢迎${name}`)
  })
}

// 退出功能
const layer = layui.layer
$('#btnLogout').on('click', function () {
  layer.confirm('确认退出登录吗？', { icon: 3, title: '提示' }, function (index) {
    //do something
    localStorage.removeItem('token')
    location.href = '/login.html'

    layer.close(index);
  });
})
$('body').on('click', '.btn_delete', function () {
  let id = $(this).attr('data-id')
  console.log(id);
  axios.get('/my/article/deletecate/' + id).then(({ data: { status, message } }) => {
    if (status !== 0) {
      return layer.msg(message)
    }
    layer.msg(message)
    fn()
  })
})